#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2024/3/8 20:00
# @Author  : jeff
# @FileName: user_model
from sqlalchemy.orm import declarative_base, relationship
from sqlalchemy.sql import expression

from src.model.base_model import BaseModel, db


class User(BaseModel):
    __tablename__ = 'Users'

    user_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    user_name = db.Column(db.String(255), nullable=False, unique=True)
    pass_word = db.Column(db.String(255), nullable=False)
    email = db.Column(db.String(255))
    role_id = db.Column(db.Integer, nullable=True)
    is_deleted = db.Column(db.Boolean, server_default=expression.false())

    @classmethod
    def query_by_user(cls, username, password):
        return cls.query.filter_by(user_name=username, pass_word=password).all()
